from django.shortcuts import render
from django.http import  HttpResponse
from django.views.decorators.csrf import csrf_exempt
from blog.models import Article
def index(request):
    ars=  Article.objects.all();
    #判断用户是否登陆
    isLogin=False
    if request.user.is_authenticated():
        isLogin=True
    return render(request,"home.html",{'ars':ars,'idLogin':isLogin})
def add(request):
    a=request.GET['a']
    b=request.GET['b']
    c=int(a)+int(b)
    return HttpResponse(str(c))
# Create your views here.
def add2(request,a,b):
    c = int(a) + int(b)
    return HttpResponse(str(c))
@csrf_exempt
def saveArticle(request):
    if request.method=='GET':
        return HttpResponse("请用post提交");
    a=request.POST['title']
    b=request.POST['content']
    b=b.replace("\n","<br>").replace(" ","&nbsp;")
    article=Article(title=a,content=b)
    article.save()
    return HttpResponse("0")

def addArticle(request):
   if request.user.is_authenticated:
        return render(request,"addArticle.html")
   else:
        return HttpResponse("请先登录")